import request from '@/plugins/axios.js';

// 获取频道新闻推荐
export const getArticles = (data) => {
  return request({
    method: 'get',
    url: '/v1_1/articles',
    needToken: true,
    params: {
      channel_id: data.channel_id,
      timestamp: data.timestamp,
      with_top: data.with_top,
    },
  });
};

// 获取所有频道
export const getAllChannels = () => {
  return request({
    method: 'get',
    url: '/v1_0/channels',
  });
};

// 添加频道
export const addUserChannel = (channels) => {
  console.log(channels);
  return request({
    method: 'patch',
    url: '/v1_0/user/channels',
    data: { channels: channels },
    needToken: true,
  });
};

// 删除用户指定频道
export const deleteUserChannel = (target) => {
  return request({
    method: 'delete',
    url: `/v1_0/user/channels/${target}`,
    needToken: true,
  });
};

// 获取文章详情
export const getArticleById = (articleId) => {
  return request({
    method: 'get',
    url: `/v1_0/articles/${articleId}`,
    needToken: true,
  });
};

// 收藏文章
export const addCollect = (target) => {
  return request({
    method: 'POST',
    url: '/v1_0/article/collections',
    data: {
      target,
    },
    needToken: true,
  });
};

// 取消收藏文章
export const deleteCollect = (target) => {
  return request({
    method: 'delete',
    url: `/v1_0/article/collections/${target}`,
    needToken: true,
  });
};

// 文章点赞
export const addLike = (target) => {
  return request({
    method: 'POST',
    url: '/v1_0/article/likings',
    data: {
      target,
    },
    needToken: true,
  });
};

// 取消文章点赞
export const deleteLike = (target) => {
  return request({
    method: 'DELETE',
    url: `/v1_0/article/likings/${target}`,
    needToken: true,
  });
};
